<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Object方法</title>
</head>
<body>
    
    <script>
        
        +function () {

            // -> Object.assign 赋值源对象的可枚举属性到目标对象 -> 这是一个会覆盖的方法 
            var obj = {name: 'ws',job: 'designer',from: 'HeNan'};
            var s = {name: 'wwwww',from: 'BeiJing'};
            var n = Object.assign(obj,s);
            console.log(obj,n);

        } ();

        +function () {

            // -> Object.create(p) 继承 + 创建一个以 p 为原型的对象 
            var obj = {name: 'ws',job: 'designer',from: 'HeNan'};
            var o = Object.create(obj);
            console.log(o.name);

        } ();


        +function () {

            // -> Object.entries(o) 返回的是一个数组 数组包含的是 属性和值得键值对   [[name,42],[age,10]] 
            var obj = {name: 'ws',job: 'designer',from: 'HeNan'};
            var ary = Object.entries(obj);
            console.log(ary);

        } ();

        +function () {

            // -> Object.freeze(o) 冻结对象 不能删除和更改属性值 但会一个和冻结一模一样的对象
            var obj = {name: 'ws',job: 'designer',from: 'HeNan'};
            var o = Object.freeze(obj);
            o.name = 'wwwwwww';
            o.job = 'xxxxx';
            console.log(o);

        } ();

        +function () {

            // -> Object.getPrototypeOf() 得到对象的原型
            var obj = {name: 'ws',job: 'designer',from: 'HeNan'};
            var o = Object.create(obj);
            console.log(o.__proto__ === Object.getPrototypeOf(o)); // true

        } ();

        +function () {

            // -> Object.is() 方法判断两个值是否是相同的值  不会做隐式转换
            var obj1 = {name: 'ws',job: 'designer',from: 'HeNan'};
            var obj2 = {name: 'ws',job: 'designer',from: 'HeNan'};            
            console.log(Object.is(obj1,obj2)); // false
            console.log(Object.is("foo","foo")); // true
            console.log(Object.is([],[])); // false
            console.log(Object.is(null,null)); // true
            console.log(Object.is(false,false)); // true
            console.log(Object.is(NaN,NaN)); // true
            console.log(Object.is("1",1)); // false

        } ();

        +function () {

            // -> Object.keys(obj) 遍历所有可枚举【属性】的字符串数组 forin 
            var obj = {name: 'ws',job: 'designer',from: 'HeNan'};
            console.log(Object.keys(obj)); // ["name","job","from"]
            var arr = ["name","job","from"];
            console.log(Object.keys(arr)); // ["0","1","2"]

            // Object.getOwnPropertyNames() 也是遍历属性 包含不可枚举的属性
            var arr = ["name","age","job","from"];
            console.log(Object.getOwnPropertyNames(arr)); // ["0", "1", "2", "3", "length"] length是不可枚举的属性
            
        } ();

    
    </script>
</body>
</html>